package com.class05.jdk8.yxy03.stream;

import com.class05.jdk8.yxy02.reference.data.Employee;
import com.class05.jdk8.yxy02.reference.data.EmployeeData;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * @ClassDescription:
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2023/11/19 10:09
 */
public class StreamAPITest {
//    创建 Stream方式一：通过集合
    @Test
    public void test1(){
        List<Employee> list = EmployeeData.getEmployees();
        //        default Stream<E> stream() : 返回一个顺序流
        Stream<Employee> stream = list.stream();
        //        default Stream<E> parallelStream() : 返回一个并行流
        Stream<Employee> employeeStream = list.parallelStream();
        System.out.println(stream);
        System.out.println(employeeStream);



    }
//    创建  Stream方式二：通过数组
    @Test
    public void test2(){
        //调用Arrays类的static <T> Stream<T> stream(T[] array): 返回一个流
        Integer[] arr = {1, 2, 3, 4, 5};
        Stream<Integer> stream = Arrays.stream(arr);

        int[] arr1 = {1, 2, 3, 4, 5};
        IntStream stream1 = Arrays.stream(arr1);

    }
//    创建  Stream方式三：通过Stream的of()
    public void test3(){
        Stream<String> stream = Stream.of("AA", "BB", "CC", "SS", "DD");
    }

}
